package com.pinla.util.IPparse;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.pinla.areamanager.vo.AreaMgrInfo;
import com.pinla.util.UtilSingleton;

public class UtilIP {

	/**
	 * @param args
	 */
	 @SuppressWarnings({ "unused", "unchecked" })
	public static Map getCity(String ip) {
		//指定纯真数据库的文件名，所在文件夹  
	      IPSeeker  iPSeeker=new IPSeeker(UtilSingleton.ipFileName,UtilSingleton.ipDataBasePath);  
	      String city="";
	      Map map=new HashMap();
	      List list=UtilSingleton.getList();
		  String country=iPSeeker.getIPLocation(ip).getCountry();
	      Iterator it=list.iterator();
	      while(it.hasNext()){
			AreaMgrInfo o=(AreaMgrInfo) it.next();
			if(o.getAreaCode().contains(country)){
				map.put(o.getAreaCode(), city=o.getAreaName());
			}
	      }

		  //测试IP 58.20.43.13   
//	     String testIp="58.20.43.13";
//		System.out.println(iPSeeker.getIPLocation(testIp).getCountry()+":"+iPSeeker.getIPLocation(testIp).getArea());
		
     return map;
	}

}
